
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ConfigProvider } from '../../providers/config/config';
import { HttpserviesProvider } from '../../providers/httpservies/httpservies';
import { Http,Jsonp } from '@angular/http';
import { SearchPage } from '../search/search';
import { GoodsdetailPage } from '../goodsdetail/goodsdetail';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {

  public GoodsdetailPage = GoodsdetailPage;
  public list = [];
  public listWidth = '';
  public focusList = []; //轮播图数据
  public bestList = [];  //精品推荐
  public hotList = [];   //热门商品

  constructor(public navCtrl: NavController,public http : Http, public config : ConfigProvider, public httpServies : HttpserviesProvider) {
    
    //1.请求轮播数据
    this.requestFocusData();

    //2.请求精品推荐数据
    this.requestBestData();

    //3.请求热门商品数据
    this.requestHotData();

  }

  //请求轮播图片
  requestFocusData(){
    this.httpServies.requestData('api/focus',(data)=>{
      this.focusList = data.result;
    });
  }

  //请求精品推荐数据
  requestBestData(){
    //http://39.108.159.135/api/plist?is_best=1
    this.httpServies.requestData('api/plist?is_best=1',(data)=>{
      this.bestList = data.result;
      this.listWidth = this.bestList.length * 93 + 'px'; //计算总的宽度
    });
  }

  //请求热门商品数据
  requestHotData(){
    //http://39.108.159.135/api/plist?is_hot=1
    this.httpServies.requestData('api/plist?is_hot=1',(data)=>{
      this.hotList = data.result;
    });
  }

  // 跳转至搜索页面
  goSearchPage(){
    this.navCtrl.push(SearchPage);
  }

}
